package container {
	import components.Checkbox;
	import components.Combobox;
	import components.DecalDisplay;
	import components.Label;
	
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TextEvent;
	import flash.text.TextField;
	
	import managers.GlobalDecalSheetManager;
	
	public class WindowWheelParameters extends Sprite {
		
		private var boxButtonClose:				DecalDisplay;
		private var boxSelectAuto:				DecalDisplay;
		private var boxButtonFitting:			DecalDisplay;
		private var labelOriginal:				Label;
		private var labelFactory:				Label;
		private var labelCustom:				Label;
		private var labelTags:					Label;
		private var labelCount:					Label;
		
		private var defaultCountText:			String;
		private var count:						uint;
		
		private var Labels: Array = new Array("Label-WheelParameters_Title");
		
		private const DecalNameOver:String = "Over";
		private const DecalNameDown:String = "Down";
		
		public function WindowWheelParameters(window: DecalDisplay)	{
			visible = false;
			count = 0;
			addComponents(window, Labels);
			visible = true;
		}
		private function addComponents(window: DecalDisplay, labelComponents: Array):void {
			
			addChild(window);
			
			boxButtonClose = new DecalDisplay("Box-WheelParameters_ButtonClose");
			addChild(boxButtonClose);
			boxButtonClose.buttonMode = true;
			boxButtonClose.addEventListener(MouseEvent.MOUSE_OVER, ButtonOver);
			
			boxSelectAuto = new DecalDisplay("Box-WheelParameters_SelectAuto");
			addChild(boxSelectAuto);
			boxSelectAuto.buttonMode = true;
			boxSelectAuto.addEventListener(MouseEvent.MOUSE_OVER, ButtonOver);
			
			boxButtonFitting = new DecalDisplay("Box-WheelParameters_ButtonFitting");
			addChild(boxButtonFitting);
			boxButtonFitting.buttonMode = true;
			boxButtonFitting.addEventListener(MouseEvent.MOUSE_OVER, ButtonOver);
			boxButtonFitting.addEventListener(MouseEvent.MOUSE_DOWN, ButtonDown);
			
			for (var i:int = 0; i < labelComponents.length; i++){
				var TempLabel: Label = new Label(labelComponents[i]);
				addChild(TempLabel);
			}
			
			labelCount = new Label("Label-WheelParameters_SelectCount");
			defaultCountText = labelCount.text;
			labelCount.text = defaultCountText +" "+ count;
			addChild(labelCount);
			
			var subWindowFactory:Sprite = new Sprite();
			var subWindowBG: DecalDisplay = new DecalDisplay("Box-WheelParameters_SubWindow");
			subWindowFactory.addChild(subWindowBG);
			
			var subLabels: Array = ["Label-WheelParameters_FactoryParameters", "Label-WheelParameters_Variants"];
			for (var j:int = 0; j < subLabels.length; j++){
				var TempLabel1: Label = new Label(subLabels[j]);
				subWindowFactory.addChild(TempLabel1);
			}
			var tempFactoryBox:DecalDisplay = new DecalDisplay("Box-WheelParameters_CheckboxParametersFactory");
			//var tempFactoryLabel:DecalDisplay = new DecalDisplay("Box-WheelParameters_CheckboxParametersFactory");
			var tempCheckbox:Checkbox = new Checkbox(true);
			tempCheckbox.x = tempFactoryBox.x;
			tempCheckbox.y = tempFactoryBox.y;
			subWindowFactory.addChild(tempCheckbox);
			
			var tempVariantsBox:DecalDisplay = new DecalDisplay("Box-WheelParameters_CheckboxParametersVariants");
			var tempCheckboxV:Checkbox = new Checkbox(false);
			tempCheckboxV.x = tempVariantsBox.x;
			tempCheckboxV.y = tempVariantsBox.y;
			subWindowFactory.addChild(tempCheckboxV);
			subWindowFactory.visible = false;
			addChild(subWindowFactory);
			
			labelOriginal = new Label("Label-WheelParameters_Original");
			labelOriginal.htmlText = "<a href='event:'>"+labelOriginal.text + "</a>"
			addChild(labelOriginal);
			labelOriginal.addEventListener(TextEvent.LINK, showOriginal);
			labelFactory = new Label("Label-WheelParameters_Factory");
			labelFactory.htmlText = "<a href='event:'>"+labelFactory.text + "</a>"
			addChild(labelFactory);
			labelFactory.addEventListener(TextEvent.LINK, showFactory);
			labelCustom = new Label("Label-WheelParameters_Custom");
			labelCustom.htmlText = "<a href='event:'>"+labelCustom.text + "</a>"
			addChild(labelCustom);
			var moveLabelCustom:Tween;
			labelCustom.addEventListener(TextEvent.LINK, showCustom);
			labelTags = new Label("Label-WheelParameters_Tags");
			labelTags.htmlText = "<a href='event:'>"+labelTags.text + "</a>"
			addChild(labelTags);
			var moveLabelTags:Tween;
			labelTags.addEventListener(TextEvent.LINK, showTags);
			
			var defaultFactoryY:int = labelFactory.y;
			var defaultCustomY:int = labelCustom.y;
			var defaultTagsY:int = labelTags.y;
			
			function showOriginal(e:TextEvent):void {
				trace("клик");
			}
			function showFactory(e:TextEvent):void {
				trace("клик1");
				if (!subWindowFactory.visible){
					subWindowFactory.visible = true;
					moveLabelCustom = new Tween(labelCustom, "y", Strong.easeInOut, defaultCustomY, defaultCustomY + 170, 0.2, true);
					moveLabelTags = new Tween(labelTags, "y", Strong.easeInOut, defaultTagsY, defaultTagsY + 170, 0.2, true);
				}
			}
			function showCustom(e:TextEvent):void {
				trace("клик3");
				if (subWindowFactory.visible){
					subWindowFactory.visible = false;
					moveLabelCustom = new Tween(labelCustom, "y", Strong.easeInOut, defaultCustomY + 170, defaultCustomY, 0.2, true);
				}
			}
			function showTags(e:TextEvent):void {
				trace("клик4");
			}
			
			
			
		}
		private function ButtonOver(e:MouseEvent):void {
			e.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER, ButtonOver);
			e.currentTarget.src = e.currentTarget.defaultSrc+DecalNameOver;
			e.currentTarget.addEventListener(MouseEvent.MOUSE_OUT, ButtonOut);
		}
		private function ButtonOut(e:MouseEvent):void {
			e.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, ButtonOut);
			e.currentTarget.src = e.currentTarget.defaultSrc;
			e.currentTarget.addEventListener(MouseEvent.MOUSE_OVER, ButtonOver);
		}
		private function ButtonDown(e:MouseEvent):void {
			e.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN, ButtonOver);
			e.currentTarget.src = e.currentTarget.defaultSrc+DecalNameDown;
			e.currentTarget.addEventListener(MouseEvent.MOUSE_UP, ButtonUp);
		}
		private function ButtonUp(e:MouseEvent):void {
			e.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, ButtonUp);
			e.currentTarget.src = e.currentTarget.defaultSrc+DecalNameOver;
			e.currentTarget.addEventListener(MouseEvent.MOUSE_OVER, ButtonDown);
		}
	}
}